package com.atguigu.daijia.driver.chain.impl;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.chain.StartServiceChain;
import com.atguigu.daijia.driver.chain.StopServiceChain;
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 山顶洞人郑某
 * @className DriverInfoChainImpl.java 司机信息服务责任链
 * @date 2024 09 13
 */
@Component
@Order(1) //注入优先级
public class DriverInfoChainImpl implements StartServiceChain, StopServiceChain {
    @Autowired
    private DriverInfoFeignClient driverInfoFeignClient;
    /**
     * 开始接单后当前服务要执行的内容
     *
     * @param driverId
     */
    @Override
    public void startService(Long driverId) {
   //1.查询司机是否认证
        Result<DriverLoginVo> driverLoginInfo = driverInfoFeignClient.getDriverLoginInfo(driverId);
        if (driverLoginInfo.getData().getAuthStatus()!=2) {
            throw new GuiguException(ResultCodeEnum.AUTH_ERROR);
        }

        //2.查询司机当日是否人脸识别
        Result<Boolean> faceRecognition = driverInfoFeignClient.isFaceRecognition(driverId);
        if (BooleanUtils.isFalse(faceRecognition.getData())) {
            throw new GuiguException(ResultCodeEnum.FACE_ERROR);
        }

        //3.更新司机接单状态 1 开始接单
        driverInfoFeignClient.updateServiceStatus(driverId,1);
    }

    /**
     * 停止接单服务后各服务需要做的业务
     *
     * @param driverId
     */
    @Override
    public void stopService(Long driverId) {
        //更新司机接单状态0
        driverInfoFeignClient.updateServiceStatus(driverId,0);
    }
}
